using System;using System.Text;using System.Drawing;using System.Drawing.Imaging;using System.Drawing.Drawing2D;using System.ComponentModel;using System.Windows.Forms;using System.Windows.Forms.Design;using System.Runtime.InteropServices;namespace EasyProgressBar{ partial class EasyProgressBar { [ToolboxItem(false)] partial class DropDownProgress : UserControl { #region API #region Symbolic Constants /// <summary> /// 当窗口显示区域的一部分显示内容或者全部变为“无效”,以致于必须“更新画面”时,将由这个消息通知程序。 /// </summary> private const int WM_PAINT = 0x000F; /// <summary> /// 是窗体客户区以外的重绘消息 /// </summary> private const int WM_NCPAINT = 0x0085; /// <summary> /// 消息是在指示HWND的整个背景窗体需要被擦除的时候才发送的。 /// </summary> private const int WM_ERASEBKGND = 0x0014; #endregion #region UnmanagedMethods /// <summary> /// 该函数检索一指定窗口的客户区域或整个屏幕的显示设备上下文环境的句柄,以后可以在GDI函数中使用该句柄来在设备上下文环境中绘图。 /// </summary> /// <param name="hwnd"></param> /// <returns></returns> [DllImport("user32", CharSet = CharSet.Auto)] internal static extern IntPtr GetDC( IntPtr hwnd); /// <summary> /// 函数释放设备上下文环境(DC)供其他应用程序使用。函数的效果与设备上下文环境类型有关。它只释放公用的和设备上下文环境,对于类或私有的则无效。 /// </summary> /// <param name="hwnd"></param> /// <param name="hdc"></param> /// <returns></returns> [DllImport("user32", CharSet = CharSet.Auto)] internal static extern int ReleaseDC( IntPtr hwnd, IntPtr hdc); #endregion #endregion #region Instance Members /// <summary> /// 用于显示 Windows 窗体,或者在设计模式下在属性网格控件的下拉区域中显示控件。 /// </summary> private IWindowsFormsEditorService editorService = null; private ColorizerProgress colorizer = null; #endregion #region Constructor public DropDownProgress() { InitializeComponent(); } public DropDownProgress(object value, IWindowsFormsEditorService editorService) : this() { this.editorService = editorService; if (value is ColorizerProgress) { this.colorizer = value as ColorizerProgress; } } #endregion #region Destructor ~DropDownProgress() { GC.SuppressFinalize(this); } #endregion #region Property public ColorizerProgress Colorizer { get { return colorizer = new ColorizerProgress((byte)redTrackBar.Value, (byte)greenTrackBar.Value, (byte)blueTrackBar.Value, (byte)alphaTrackBar.Value, colorizer.IsColorizerEnabled, colorizer.IsTransparencyEnabled); } } #endregion #region Override Methods /// <summary> /// Uygulamaya gelecek windows mesajları burda işlenir. /// </summary> /// <param name="m">Windows mesaj parametresi</param> protected override void WndProc(ref Message m) { // Kendi process işlemlerini yapsın. base.WndProc(ref m); // Daha sonra bizim metodumuzuda çağırsın. DrawBorder(ref m, this.Width, this.Height); } #endregion #region Helper Methods /// <summary> /// Kontrolümüz için kenarlık çiziyoruz. /// </summary> /// <param name="message">Kontrolümüzün Win32 mesaj işleme komutu</param> /// <param name="width">Kontrolümüzün genişlik değeri</param> /// <param name="height">Kontrolümüzün yükseklik değeri</param> private void DrawBorder(ref Message message, int width, int height) { if (message.Msg == WM_NCPAINT || message.Msg == WM_ERASEBKGND || message.Msg == WM_PAINT) { IntPtr hdc = GetDC(message.HWnd); if (hdc != IntPtr.Zero) { Graphics graphics = Graphics.FromHdc(hdc); Rectangle rectangle = new Rectangle(0, 0, width, height); ControlPaint.DrawBorder(graphics, rectangle, SystemColors.ActiveBorder, this.Padding.Left, ButtonBorderStyle.Solid, SystemColors.ActiveBorder, this.Padding.Top, ButtonBorderStyle.Solid, SystemColors.ActiveBorder, this.Padding.Right, ButtonBorderStyle.Solid, SystemColors.ActiveBorder, this.Padding.Bottom, ButtonBorderStyle.Solid); // Grafik nesnesinden kurtul. ReleaseDC(message.HWnd, hdc); } } } #endregion #region Event Handlers private void DropDownProgress_Load(object sender, EventArgs e) { redTrackBar.Value = colorizer.Red; greenTrackBar.Value = colorizer.Green; blueTrackBar.Value = colorizer.Blue; alphaTrackBar.Value = colorizer.Alpha; } private void closeDialogBtn_Click(object sender, EventArgs e) { editorService.CloseDropDown(); } private void TRACKBAR_VALUE_CHANGED(object sender, EventArgs e) { if (sender is TrackBar) { string result = null; TrackBar ctrl = (TrackBar)sender; if (ctrl.Value == 0) result = "Min"; else if (ctrl.Value == 255) result = "Max"; switch (ctrl.Name) { case "redTrackBar": label1.Text = String.Format("Red: {0}", result ?? ctrl.Value.ToString()); break; case "greenTrackBar": label2.Text = String.Format("Green: {0}", result ?? ctrl.Value.ToString()); break; case "blueTrackBar": label3.Text = String.Format("Blue: {0}", result ?? ctrl.Value.ToString()); break; default: label4.Text = String.Format("Alpha: {0}", result ?? ctrl.Value.ToString()); break; } } } #endregion } }}
下载winform 自定义进度条控件 源码 EasyProgressBar用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论